<%@ page language="java" contentType="text/javascript; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import='java.sql.*' %>
<%@page import="java.util.ArrayList"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="net.sf.json.JSONSerializer"%>
<%@page import="net.sf.json.JSONArray"%>

<%String callback = request.getParameter("callback");%>
<%=callback %> (<%

	String id = request.getParameter("id");

	String name = new String(request.getParameter("name").getBytes("8859_1"), "utf-8"); 
	String email = request.getParameter("email");
	String age = request.getParameter("age");
	String gender = request.getParameter("gender");
	String jointheme = request.getParameter("jointheme");
	String cacao = new String(request.getParameter("cacao").getBytes("8859_1"), "utf-8");
	
	
	
	Connection conn = null;
	PreparedStatement pstmt = null;
	
	try{
		Class.forName("com.mysql.jdbc.Driver");
		conn = DriverManager.getConnection(
			"jdbc:mysql://localhost/itscreater", "itscreater", 

"campus123");
		
		String insert = "insert into UserInfo" +
						"(ID, Name, Email, Age, Gender, Cacao) " +
						"values (?, ?, ?, ?, ?, ?);";
		pstmt = conn.prepareStatement(insert);
		pstmt.setString(1, id);
		pstmt.setString(2, name);
		pstmt.setString(3, email);
		pstmt.setString(4, age);
		pstmt.setString(5, gender);
		pstmt.setString(6, cacao);
		pstmt.executeUpdate();
		
		
		String select = "select * from UserInfo where ID = ?;";
		pstmt = conn.prepareStatement(select);
		pstmt.setString(1, id);
		ResultSet rs = pstmt.executeQuery();
		rs.next();
		
		String getname = rs.getString("Name");
		String getemail = rs.getString("Email");
		String getage = rs.getString("Age");
		String getgender = rs.getString("Gender");
		String getintroduction = rs.getString("Introduction");
		String getcacao = rs.getString("Cacao");
		
		JSONObject jo = new JSONObject();		
		jo.put("success", "true");
		
		jo.put("ID", id);
		jo.put("Name", getname);
		jo.put("Email", getemail);
		jo.put("Age", getage);
		jo.put("Gender", getgender);
		jo.put("Introduction", getintroduction);
		jo.put("Cacao", getcacao);

		out.print(jo);
	}
	
	finally{
		try{
			pstmt.close();
		}
		catch (Exception ignored){
		}
		try{
			conn.close();
		}
		catch (Exception ignored){
		}
	}
%>);